package com.woniuxy.listener;

import com.rabbitmq.client.Channel;
import com.woniuxy.entity.Mail;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


/**
 * @Author: 马宇航
 * @Description: TODO
 * @DateTime: 22/10/20/0020 16:36
 * @Component: 成都蜗牛学苑
 **/
@Component
@RabbitListener(queues = "delayQueue")
public class DelayListener {
    @RabbitHandler
    public void handel(Mail mail, Channel channel, Message message) throws IOException {
        System.out.println("DelayListener.handel:延迟消息接受成功");
        channel.basicQos(1);
//        System.out.println("答应延迟消息头："+message.getMessageProperties().getHeader("x-delay").toString());
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        System.out.println("消息接受完成");
    }
}
